#include<bits/stdc++.h>
using namespace std;

struct node {
    int val;
    node *lc, *rc;
};

int n;


node* insertBST(node* &root, int x) {
    node *t = root;

    if(t != NULL) {
        if(x > t->val)
            t->lc = insertBST(t->lc, x);
        else
            t->rc = insertBST(t->rc, x);
    } else {
        t = new node;
        t->val = x;
        t->lc = t->rc = NULL;
    }
    return t;
}


void preOrd(node *t) {
    if(!t)	return ;
    cout << t->val << " ";
    preOrd(t->lc);
    preOrd(t->rc);
}


vector<int> bfs(node *root) {
    vector<int> res;

    queue<node*> q;
    q.push(root);

    while(!q.empty()) {
        node *t = q.front();
        q.pop();

        res.push_back(t->val);

        if(t->lc)
            q.push(t->lc);
        if(t->rc)
            q.push(t->rc);
    }
    return res;
}


bool flag = 0;
int getDep(node* t) {
    if(flag)	return -1;

    if(!t)	return 0;

    int ld = getDep(t->lc);
    int rd = getDep(t->rc);

    if(ld < rd || ld - rd > 1) {
        flag = 1;
        return -1;
    }

    return max(ld, rd) + 1;
}


signed main() {

    node *t = NULL;
    cin >> n;
    int x;
    for(int i = 1; i <= n; i++) {
        cin >> x;
        t = insertBST(t, x);
    }

    vector<int> ans = bfs(t);

    for(int i = 0; i < ans.size(); i++) {
        if(!i)
            cout << ans[i];
        else
            cout << " " << ans[i];
    }

    int ld = getDep(t->lc);
    int rd = getDep(t->rc);

    if(ld < rd || abs(ld - rd) > 1)
        cout << "\nNO";
    else
        cout << "\nYES";

    return 0;
}

